#pragma once
#ifndef LIT__EDITOR__MESH__SELECTER__DIALOG__HH__
#define LIT__EDITOR__MESH__SELECTER__DIALOG__HH__

#include <Ogre.h>
#include <qicon.h>
#include <qdialog.h>
#include <qlistwidget.h>
#include <qmessagebox.h>
#include "ui_MeshSelecterDialog.h"
#include "LitEditorPrerequisites.h"
#include <LitResourcesList.h>
#include <LitCacheManager.h>
#include <LitInitialiser.h>
#include <LitRoot.h>

namespace Lit
{
	namespace Editor
	{
		class LIT_API MeshRenderScene
		{
			Ogre::TexturePtr		mTexture;
			Ogre::Light*			mLight;
			Ogre::Camera*			mCamera;
			Ogre::Viewport*			mViewport;
			Ogre::Entity*			mEntity;
			Ogre::RenderTexture *	mRenderTex;
			Ogre::SceneManager *	mSceneMgr;

		public:
			MeshRenderScene( const Lit::Color & bgcolor = Lit::Color::Black );
			~MeshRenderScene();

			Lit::FilePath createMeshSnapshot( const std::string &mesh );
		};
		class LIT_API MeshIconDatabase : public Initialiser
		{
		private:
			MeshIconDatabase( const MeshIconDatabase& rk ) : Initialiser(rk){}
			MeshIconDatabase& operator=(const MeshIconDatabase& rk ){return *this;}
			static void _dummyCallback(const std::string &name, size_t current, size_t num_mesh ){}

		public:
			typedef boost::function<void(const std::string&, size_t, size_t)> MeshCreationCallback;

			MeshIconDatabase();
			~MeshIconDatabase();

			static MeshIconDatabase& Instance()
			{
				static MeshIconDatabase instance;
				return instance;
			}
			void createMeshSnapshot( const std::string &mesh, MeshCreationCallback cbk = boost::bind(&MeshIconDatabase::_dummyCallback, _1,_2,_3) );
			void initialise( MeshCreationCallback callback = boost::bind(&MeshIconDatabase::_dummyCallback, _1,_2,_3) );
			void shutdown( );

			QIcon getIcon( const std::string &mesh );
		protected:
			std::map<std::string, Lit::FilePath> mIcons;
		};
		class LIT_API MeshSelecterDialog : public QDialog
		{
			Q_OBJECT
		public:

			void prepareMeshList(const std::string &filter = "*");
		public:
			MeshSelecterDialog( QWidget* parent, Lit::ResourcesListPtr res ) ;
			~MeshSelecterDialog( );

			std::string exec( const std::string &filter = "*" );

		protected slots:
			void acceptSelection(QListWidgetItem*);
			void updateSearchFilters(const QString &);

		private:	
			Ui::SelectMeshDialog ui;
			Lit::ResourcesListPtr mResources;
		};
	};
};

#endif